/**
 * 菜单接口
 */

const Router = require("koa-router");
const router = new Router();
const auth = require("../middleware/auth.js");
const passport = require("koa-passport");

const { SystemMenuController } = require("../controller/sys_menu.js");

router.get(
  "/v1/system/menu/list",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:query"),
  SystemMenuController.sysMenuList
);

router.post(
  "/v1/system/menu/add",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:add"),
  SystemMenuController.sysMenuAdd
);
router.post(
  "/v1/system/menu/delete",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:remove"),
  SystemMenuController.sysMenuDel
);
router.post(
  "/v1/system/menu/deleteByIds",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:remove"),
  SystemMenuController.sysMenuDelByIds
);
router.put(
  "/v1/system/menu/update",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:edit"),
  SystemMenuController.sysMenuUpd
);
// 获取菜单信息
router.post(
  "/v1/system/getRouters",
  passport.authenticate("jwt", { session: false }),
  SystemMenuController.getRouters
);
// 获取用户的权限信息
router.post(
  "/v1/system/getPermissions",
  passport.authenticate("jwt", { session: false }),
  SystemMenuController.sysPermissions
);
// 获取菜单id
router.get(
  "/v1/system/menu/getById",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:query"),
  SystemMenuController.sysMenuById
);

// 通过role_id获取菜单
router.post(
  "/v1/system/menu/roleMenuTreeselect",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:query"),
  SystemMenuController.roleMenuTreeselect
);

// 通过role_id获取菜单
router.post(
  "/v1/system/menu/treeselect",
  passport.authenticate("jwt", { session: false }),
  auth("system:menu:query"),
  SystemMenuController.treeselect
);

module.exports = router;
